<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Traits\HasDateTimeFormatter;

class OrderAddress extends Model
{
    use HasDateTimeFormatter;
    
    protected $table = 'ims_yz_order_address';
    protected $guarded = [''];
    
    // 禁用Laravel的自动时间戳管理
    public $timestamps = false;
    
    /**
     * 关联订单
     */
    public function order()
    {
        return $this->belongsTo(Order::class, 'order_id', 'id');
    }
    
    /**
     * 按订单ID筛选
     */
    public function scopeByOrderId($query, $orderId)
    {
        return $query->where('order_id', $orderId);
    }
    
    /**
     * 获取完整地址
     */
    public function getFullAddressAttribute()
    {
        return $this->province . $this->city . $this->district . $this->address;
    }
}
